import {defineStore} from "pinia";
import https from "../utils/https";

export const useHomes = defineStore("homes",{
    state:()=>{
        return{
            articleList:[] as any,
            swiperList:[] as any,
            CategoryList:[] as any,
            articleListall:[] as any,
            tagList:[] as any,
            articleTatol:0,
            knowleageList:[] as any,
        }
    },
    actions:{
        // 获取所有文章接口 https://creationapi.shbwyz.com/api/article/all/recommend 
        async getArticle() {
            let res = await https.get('/api/article/all/recommend');
            // console.log(res.data.data,"article")
            if(res.status==200){
                //所有文章数据
                this.articleList = res.data.data
                //轮播图数据筛选
                this.swiperList = res.data.data.filter((v:any)=>v.cover)
            }
        },
       // 获取分类 https://creationapi.shbwyz.com/api/category?articleStatus=publish
        async getcategory (){
            let res = await https.get("/api/category",{params:{articleStatus:"publush"}})
            // console.log(res.data.data,"category")
            if(res.status==200){
                this.CategoryList = res.data.data
            }
        },
        async getArtitemall(){
            let res = await https.get("/api/article", { params: { page:1, pageSize:100 } })
            // console.log(res.data.data[0],"itemsall")
            if(res.status==200){
                this.articleListall = res.data.data[0]
                this.articleTatol = res.data.data[1]
            }
        },
        async gettags(){
            // 获取标签  https://creationapi.shbwyz.com/api/tag?articleStatus=publish
            let res = await https.get("/api/tag",{params:{articleStatus:'publish'}});
            // console.log(res.data.data,"tag")
            if(res.status == 200){
                this.tagList = res.data.data
            }
        },
        // 知识小测 https://creationapi.shbwyz.com/api/knowledge?page=1&pageSize=12
        async getknowleage() {
            let res = await https.get("/api/knowledge",{params:{page:1,pageSize:100,status:"publish"}})
            // console.log(res.data.data[0],"knowleageList")
            if(res.status==200){
                this.knowleageList = res.data.data[0]
            }
        }
    },
    getters:{

    }
})